<?php

/*
 * Clase Persona
 */
class Application_Models_ContactoModel 
{
    private $_nombre;
    private $_apellidos;
    private  $_sexo ;
    private  $_programa;
    private  $_universidad ;
    private  $_email;
    private  $_celular;
    private  $_pais;
    private  $_direccion;
    private  $_comentario;
    
    public function setNombre( $nombre )
    {
        $this->_nombre = $nombre;
    }
    
    public function getNombre()
    {
        return $this->_nombre;
    }

    public function setApellidos( $apellidos )
    {
        $this->_apellidos = $apellidos;
    }
    
    public function getApellidos()
    {
        return $this->_apellidos;
    }

    public function setSexo( $sexo )
    {
        $this->_sexo = $sexo;
    }
    
    public function getSexo()
    {
        return $this->_sexo;
    }
    
    public function setPrograma( $programa )
    {
        $this->_programa = $programa;
    }
    
    public function getPrograma()
    {
        return $this->_programa;
    }

    public function setUniversidad( $universidad )
    {
        $this->_universidad = $universidad;
    }
    
    public function getUniversidad()
    {
        return $this->_universidad;
    }

    public function setEmail( $email )
    {
        $this->_email = $email;
    }
    
    public function getEmail()
    {
        return $this->_email;
    }
    
    public function setCelular($celular)
    {
        $this->_celular = $celular;
    }
    
    
    public function getCelular()
    {
        return $this->_celular;
    }
    
    public function setPais($pais)
    {
        $this->_pais = $pais;
    }
    
    
    public function getPais()
    {
        return $this->_pais;
    }
    
    public function setDireccion($direccion)
    {
        $this->_direccion = $direccion;
    }
    
    public function getDireccion()
    {
        return $this->_direccion;
    }
    
    public function setComentario($comentario)
    {
        $this->_comentario = $comentario;
    }
    
    public function getComentario()
    {
        return $this->_comentario;
    }
    
    public function listContactos()       
    {
        
    }
    
    public function insertContacto()       
    {
        
       $db = new DataBase();
       $viewPers = new Application_Views_ContactoView();
        $conexion = $db->getConnection();
    $result = $conexion->executeQuery("
            call sp_RegistraContacto('".$this->_nombre."', '".$this->_apellidos."',
            ".$this->_sexo.",'".$this->_programa."','".$this->_universidad."' ,'".$this->_email."',
                ".$this->_celular.", '".$this->_pais."', '".$this->_direccion."', '".$this->_comentario."')" ) ;
    
       
        if( count($result)>0){
            require 'Components/PHPMailer/PHPMailer.php';

            //Create a new PHPMailer instance
            $mail = new PHPMailer();
            //Tell PHPMailer to use SMTP
            $mail->isSMTP();
            //Enable SMTP debugging
            // 0 = off (for production use)
            // 1 = client messages
            // 2 = client and server messages
            $mail->SMTPDebug = 2;
            //Ask for HTML-friendly debug output
            $mail->Debugoutput = 'html';
            //Set the hostname of the mail server
            $mail->Host = 'smtp.gmail.com';
            //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
            $mail->Port = 587;
            //Set the encryption system to use - ssl (deprecated) or tls
            $mail->SMTPSecure = 'tls';
            //Whether to use SMTP authentication
            $mail->SMTPAuth = true;
            //Username to use for SMTP authentication - use full email address for gmail
            $mail->Username = "dxniel27@gmail.com";
            //Password to use for SMTP authentication
            $mail->Password = "Dxasd";
            //Set who the message is to be sent from
            $mail->setFrom('dxniel127@gmail.com', 'admin');
            //Set an alternative reply-to address
            $mail->addReplyTo('dxniel127@gmail.com', 'admin');
            //Set who the message is to be sent to
            $mail->addAddress($this->_email, $this->_nombre);
            $mail->addCC('xrgerx@gmail.com', 'Roger');
            //Set the subject line
            $mail->Subject = 'Ud se a registrado correctamente1';
            //cuerpo
            $mail->Body = 'Ud se a registrado correctamente2';
            //Read an HTML message body from an external file, convert referenced images to embedded,
            //convert HTML into a basic plain-text alternative body
            //--$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
            //Replace the plain text body with one created manually
            $mail->AltBody = 'Ud se a registrado correctamente3';
            //Attach an image file
            //$mail->addAttachment('images/phpmailer_mini.gif');

            //send the message, check for errors
//            if (!$mail->send()) {
//                echo "Mailer Error: " . $mail->ErrorInfo;
//            } else {
//                echo "Message sent!";
//            }
// 
           $viewPers->showMsj();
        }else{
            $viewPers->showMsjE();
        }
                                                      
        
    }
        
}